#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=4096, maxc=345678;

void reverse(int l, int r, int *a, int ans[][2]) {
  for (int i=l, j=r; i<j; i++, j--) {
    int t;
    t=a[i], a[i]=a[j], a[j]=t;
    ans[++ans[0][0]][0] = i;
    ans[ans[0][0]][1] = j;
  }
}

void merge(int l1, int r1, int l2, int r2, int *a, int ans[][2]) {
  if (l1==r1 && l2==r2) {
    if (a[l1]>a[l2]) {
      reverse(l1, r2, a, ans);
    }
  } else {
    int i, j;
    for (i=r1, j=l2; i>=l1 && j<=r2 && a[i]>a[j]; i--, j++);
    i++, j--;
    if (i<j) {
      reverse(i, r1, a, ans);
      reverse(l2, j, a, ans);
      reverse(i, j, a, ans);
      merge(l1, i-1, i, r1, a, ans);
      merge(l2, j, j+1, r2, a, ans);
    }
  }
}

void solve(int l, int r, int *a, int ans[][2]) {
  if (l!=r) {
    int mid=(l+r)/2;
    solve(l, mid, a, ans);
    solve(mid+1, r, a, ans);
    merge(l, mid, mid+1, r, a, ans);
  }
}

int main() {
  freopen("swap.in", "r", stdin);
  freopen("swap.out", "w", stdout);

  static int a[maxn+1], b[maxn+1], ans[2][maxc+1][2];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d", a+i);
  }
  for (int i=1; i<=n; i++) {
    scanf("%d", b+i);
  }

  solve(1, n, a, ans[0]);
  solve(1, n, b, ans[1]);

  printf("%d\n", ans[0][0][0]+ans[1][0][0]);
  for (int i=1; i<=ans[0][0][0]; i++) {
    printf("%d %d\n", ans[0][i][0], ans[0][i][1]);
  }
  for (int i=ans[1][0][0]; i>0; i--) {
    printf("%d %d\n", ans[1][i][0], ans[1][i][1]);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
